home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / TextField.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  11KB  |  233 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/TextField.c,v 41.11 2000/05/09 20:33:57 mlemos Exp $
  3.  *
  4.  * TextField.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * All Rights Reserved.
  8.  *
  9.  * $Log: TextField.c,v $
  10.  * Revision 41.11  2000/05/09 20:33:57  mlemos
  11.  * Bumped to revision 41.11
  12.  *
  13.  * Revision 1.2  2000/05/09 19:59:12  mlemos
  14.  * Merged with the branch Manuel_Lemos_fixes.
  15.  *
  16.  * Revision 1.1.2.1  1999/07/30 22:11:47  mlemos
  17.  * Initial revision.
  18.  *
  19.  *
  20.  *
  21.  */
  22.  
  23. #include "DemoCode.h"
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. #include <intuition/icclass.h>
  30. #include <gadgets/textfield.h>
  31. #include <proto/textfield.h>
  32. #include <proto/iffparse.h>
  33.  
  34. /*
  35. **      Library base pointers.
  36. **/
  37. struct Library *TextFieldBase = NULL;
  38.  
  39. /*
  40. **      Object ID's
  41. **/
  42. #define ID_RIGHTPROP 1
  43. #define ID_TEXTFIELD 2
  44.  
  45. /*
  46. **      And were in...
  47. **/
  48. VOID StartDemo( void )
  49. {
  50.         Object                  *WN_Window, *GO_Textfield, *GO_Master, *GO_RightProp;
  51.         struct Window           *win;
  52.         ULONG                   winsig = 0L, sigrec, rc;
  53.         BOOL                    running = TRUE;
  54.  
  55.         /*
  56.         **      Open the libraries. Get display information etc...
  57.         **/
  58.         if ( TextFieldBase = OpenLibrary( TEXTFIELD_NAME, TEXTFIELD_VER )) {
  59.  
  60.                 struct ClipboardHandle *clip_handle, *undo_handle;
  61.                 struct IntuiText text1_title;
  62.  
  63.                 text1_title.FrontPen = 0;
  64.                 text1_title.BackPen = 1;  /* don't really need to set for JAM1 */
  65.                 text1_title.DrawMode = JAM1;
  66.                 text1_title.LeftEdge = 0;
  67.                 text1_title.TopEdge = 0;
  68.                 text1_title.ITextFont = NULL;
  69.                 text1_title.IText = NULL;
  70.                 text1_title.NextText = NULL;
  71.  
  72.                 /* Open the clipboard; no need to verify */
  73.                 clip_handle = OpenClipboard(0);
  74.                 undo_handle = OpenClipboard(42);
  75.  
  76.                 /*
  77.                 **      Create a small window.
  78.                 **/
  79.                 WN_Window = WindowObject,
  80.                         WINDOW_Title,           "Text field",
  81.                         WINDOW_RMBTrap,         TRUE,
  82.                         WINDOW_ScaleWidth,      20,
  83.                         WINDOW_ScaleHeight,     20,
  84.                         WINDOW_AutoAspect,      TRUE,
  85.  
  86.                         WINDOW_RBorderGroup,
  87.                             VGroupObject,
  88.                                StartMember,
  89.                                   GO_RightProp = PropObject,
  90.                                      PGA_Top,        0,
  91.                                      PGA_Total,      1,
  92.                                      PGA_Visible,    1,
  93.                                      PGA_Arrows,     TRUE,
  94.                                      PGA_Freedom,    FREEVERT,
  95.                                      PGA_NewLook,    TRUE,
  96.                                      GA_ID,          ID_RIGHTPROP,
  97.                                   EndObject,
  98.                                EndMember,
  99.                             EndObject,
  100.  
  101.                         WINDOW_MasterGroup,
  102.                                 GO_Master = VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  103.                                         StartMember,
  104.                                                 GO_Textfield = ExternalObject,
  105.                                                         EXT_MinWidth,           30,
  106.                                                         EXT_MinHeight,          30,
  107.                                                         EXT_Class,              TEXTFIELD_GetClass(),
  108.                                                         EXT_NoRebuild,          TRUE,
  109.  
  110.                                                         FRM_Type,               FRTYPE_RIDGE,
  111.  
  112.                                                         GA_FollowMouse,         TRUE,
  113.                                                         GA_IntuiText,           &text1_title,
  114.                                                         GA_ID,                  ID_TEXTFIELD,
  115.  
  116.                                                         TEXTFIELD_Text,         (ULONG)"Right Amiga C - Copy\nRight Amiga X - Cut\nRight Amiga V - Paste\n",
  117.                                                         TEXTFIELD_UserAlign,    TRUE,
  118.                                                         TEXTFIELD_BlinkRate,    500000,
  119.                                                         TEXTFIELD_TabSpaces,    4,
  120.                                                         TEXTFIELD_NonPrintChars,TRUE,
  121.                                                         TEXTFIELD_ClipStream,   clip_handle,
  122.                                                         TEXTFIELD_UndoStream,   undo_handle,
  123.  
  124.                                                 EndObject,
  125.                                         EndMember,
  126.                                 EndObject,
  127.                 EndObject;
  128.  
  129.                 if ( WN_Window ) {
  130.  
  131.                         /*
  132.                         **      Open up the window.
  133.                         **/
  134.                         if ( win = WindowOpen( WN_Window )) {
  135.                                 /*
  136.                                 **      Obtain window sigmask.
  137.                                 **/
  138.                                 GetAttr( WINDOW_SigMask, WN_Window, &winsig );
  139.                                 /*
  140.                                 **      Wait for messages.
  141.                                 **/
  142.                                 ActivateGadget((struct Gadget *)GO_Textfield,win,NULL);
  143.                                 do {
  144.                                         sigrec = Wait( winsig );
  145.  
  146.                                         /*
  147.                                         **      Window signal?
  148.                                         **/
  149.                                         if ( sigrec & winsig ) {
  150.                                                 while ( WN_Window && (( rc = HandleEvent( WN_Window )) != WMHI_NOMORE )) {
  151.                                                         switch ( rc ) {
  152.  
  153.                                                                 case    WMHI_CLOSEWINDOW:
  154.                                                                         /*
  155.                                                                         **      The end.
  156.                                                                         **/
  157.                                                                         running = FALSE;
  158.                                                                         break;
  159.  
  160.                                                                 case    ID_RIGHTPROP:
  161.                                                                 {
  162.                                                                         Object *object;
  163.                                                                         ULONG top,visible,total;
  164.  
  165.                                                                         GetAttr( EXT_Object, GO_Textfield, ( ULONG * )&object);
  166.                                                                         GetAttr( TEXTFIELD_Top, object, &top);
  167.                                                                         GetAttr( PGA_Visible, GO_RightProp, &visible);
  168.                                                                         GetAttr( PGA_Total, GO_RightProp, &total);
  169.                                                                         if(visible>total)
  170.                                                                                 visible=total;
  171.                                                                         SetGadgetAttrs((struct Gadget *)object,win,NULL,
  172.                                                                                 TEXTFIELD_Top,top,
  173.                                                                                 TEXTFIELD_Visible,visible,
  174.                                                                                 TEXTFIELD_Lines,total,
  175.                                                                                 TAG_END);
  176.                                                                 }
  177.  
  178.                                                                 case    ID_TEXTFIELD:
  179.                                                                 {
  180.                                                                         Object *object;
  181.                                                                         ULONG top,visible,total;
  182.  
  183.                                                                         GetAttr( EXT_Object, GO_Textfield, ( ULONG * )&object);
  184.                                                                         GetAttr( TEXTFIELD_Top, object, &top);
  185.                                                                         GetAttr( TEXTFIELD_Visible, object, &visible);
  186.                                                                         GetAttr( TEXTFIELD_Lines, object, &total);
  187.                                                                         if(visible>total)
  188.                                                                                 visible=total;
  189.                                                                         SetGadgetAttrs((struct Gadget *)GO_RightProp,win,NULL,
  190.                                                                                 PGA_Top,top,
  191.                                                                                 PGA_Visible,visible,
  192.                                                                                 PGA_Total,total,
  193.                                                                                 TAG_END);
  194.                                                                 }
  195.                                                         }
  196.                                                 }
  197.                                         }
  198.                                 } while ( running );
  199.                         }
  200.                         /*
  201.                         **      Kill the window.
  202.                         **/
  203.                         DisposeObject( WN_Window );
  204.                 }
  205.  
  206.                 /* Close the clipboard */
  207.                 if (undo_handle) {
  208.                     CloseClipboard(undo_handle);
  209.                 }
  210.                 if (clip_handle) {
  211.                     CloseClipboard(clip_handle);
  212.                 }
  213.  
  214.                 /*
  215.                 **      Close the textfield.gadget.
  216.                 **/
  217.                 CloseLibrary( TextFieldBase );
  218.         }
  219.         else
  220.         {
  221.                 struct bguiRequest   req;
  222.  
  223.                 memset(&req,'\0',sizeof(req));
  224.                 req.br_GadgetFormat  = "_Ok";
  225.                 req.br_TextFormat    = ISEQ_C "This program requires Mark Thomas' gadgets/textfield.gadget\ninstalled in your LIBS: directory.\n\n You may find it at: " ISEQ_U ISEQ_FILL "aminet://dev/gui/textfield.lha" ISEQ_N ".";
  226.                 req.br_Flags         = BREQF_AUTO_ASPECT|BREQF_FAST_KEYS;
  227.                 req.br_ReqPos        = POS_CENTERMOUSE;
  228.                 req.br_Underscore    = '_';
  229.  
  230.                 BGUI_RequestA( NULL, &req, NULL);
  231.         }
  232. }
  233.